//
//  CaseManageTopView.m
//  International_Hospital
//
//  Created by 张城 on 16/7/6.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "CaseManageTopView.h"

#import "DoctorListModel.h"

@interface CaseManageTopView()

@property (nonatomic,strong)UILabel *name_label;
@property (nonatomic,strong)UILabel *num_label;

@property (nonatomic,strong)UILabel *sex_label;

@property (nonatomic,strong)UILabel *tel_label;

@property (nonatomic,strong)UILabel *addr_label;

@property (nonatomic,strong)NSArray<DesModel*>*dataArray;

@property (nonatomic,strong)DesModel *model;

@property (nonatomic,strong)UIImageView *picImageView;

@end

@implementation CaseManageTopView

- (instancetype)init{
    if (self = [super init]) {
        [self setupUI];
    }
    return self;
}

-(NSArray <DesModel*>*)dataArray{
    
    if (_dataArray == nil) {
        NSString *path = [[NSBundle mainBundle]pathForResource:@"DesPlist.plist" ofType:nil];
        NSArray*tempArray = [NSArray arrayWithContentsOfFile:path];
        NSMutableArray *muArray = [NSMutableArray array];
        for (NSDictionary*dict in tempArray) {
            DesModel *model = [DesModel desModelWithDict:dict];
            [muArray addObject:model];
        }
        _dataArray = muArray;
    }
    return _dataArray;
}

- (void)setupUI{
    
    
    
    self.picImageView = [[UIImageView alloc]init];
    

    
    
    
    [self addSubview:self.picImageView];
    NSFileManager *manger = [NSFileManager defaultManager];
    if ([manger fileExistsAtPath:PATH]) {
        UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfFile:PATH]];
        self.picImageView.image = image;
    }else{
        self.picImageView.image = [UIImage imageNamed:@"Bill"];
    }
    
    [self.picImageView makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(20);
        make.size.equalTo(CGSizeMake(90, 90));
    }];
    
    
    self.name_label = [[UILabel alloc]init];
    self.name_label.text = self.dataArray[0].content;
    
    self.name_label.font = [UIFont systemFontOfSize:15];
    [self addSubview:self.name_label];
    [self.name_label makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.picImageView.centerX);
        make.centerY.equalTo(CGRectGetMaxY(self.picImageView.frame)).offset(52);
    }];
    
    UIImageView * imgView1 = [[UIImageView alloc]init];
    imgView1.image = [UIImage imageNamed:@"0"];
    [self addSubview:imgView1];
    [imgView1 makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.picImageView.mas_top).offset(10);
        make.left.equalTo(self.picImageView.right).offset(10);
        make.size.equalTo(CGSizeMake(15, 15));
    }];

    self.sex_label = [[UILabel alloc]init];
    self.sex_label.text = [NSString stringWithFormat:@"性别:%@ 年龄:%@",self.dataArray[2].content,self.dataArray[3].content];
    
    [self addSubview:self.sex_label];
    self.sex_label.font = [UIFont systemFontOfSize:12];
    [self.sex_label makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(imgView1.top);
        make.left.equalTo(imgView1.right).offset(20);
    }];
    
    UIImageView * imgView2 = [[UIImageView alloc]init];
    imgView2.image = [UIImage imageNamed:@"idCard"];
    [self addSubview:imgView2];
    [imgView2 makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imgView1.bottom).offset(10);
        make.left.equalTo(self.picImageView.right).offset(10);
        make.size.equalTo(CGSizeMake(15, 15));
    }];

    self.num_label = [[UILabel alloc]init];
//    self.num_label.text = @"编号:1234567890";
    [self addSubview:self.num_label];
    self.num_label.font = [UIFont systemFontOfSize:12];
    self.num_label.text = [NSString stringWithFormat:@"病号: %@",self.dataArray[1].content];
    [self.num_label makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imgView2.top);
        make.left.equalTo(imgView2.right).offset(20);
    }];
    
    UIImageView * imgView3 = [[UIImageView alloc]init];
    imgView3.image = [UIImage imageNamed:@"phone"];
    [self addSubview:imgView3];
    [imgView3 makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imgView2.bottom).offset(10);
        make.left.equalTo(self.picImageView.right).offset(10);
        make.size.equalTo(CGSizeMake(15, 15));
    }];
    
    self.tel_label = [[UILabel alloc]init];
//    self.tel_label.text = @"电话:10987654321";
    self.tel_label.text = [NSString stringWithFormat:@"手机: %@",self.dataArray[5].content];
    [self addSubview:self.tel_label];
    self.tel_label.font = [UIFont systemFontOfSize:12];
    [self.tel_label makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imgView3.top);
        make.left.equalTo(imgView3.right).offset(20);
    }];
    
    UIImageView * imgView4 = [[UIImageView alloc]init];
    imgView4.image = [UIImage imageNamed:@"illness_rb_img_sel.png"];
    [self addSubview:imgView4];
    [imgView4 makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imgView3.bottom).offset(10);
        make.left.equalTo(self.picImageView.right).offset(11);
        make.size.equalTo(CGSizeMake(15, 15));
    }];
    
    self.addr_label = [[UILabel alloc]init];
//    self.addr_label.text = @"城市:上海市";
    [self addSubview:self.addr_label];
    self.addr_label.font = [UIFont systemFontOfSize:12];
    [self.addr_label makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imgView4.top);
        make.left.equalTo(imgView4.right).offset(20);
    }];
    self.addr_label.text = [NSString stringWithFormat:@"地址: %@",self.dataArray[4].content];
    
    UIView * lineV = [[UIView alloc]init];
    lineV.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self addSubview:lineV];
    [lineV makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width - 20);
        make.top.equalTo(self.name_label.bottom).offset(5);
        make.height.mas_equalTo(2);
    }];
    
    
    
    NSString *name = [[NSUserDefaults standardUserDefaults]objectForKey:@"姓名"];
    
    if (name) {
        self.name_label.text = name;
    }
    
    NSString *num = [[NSUserDefaults standardUserDefaults]objectForKey:@"病号"];
    if (num) {
        self.num_label.text = num;
    }
    NSString *tel = [[NSUserDefaults standardUserDefaults]objectForKey:@"手机"];
    if (tel) {
        self.tel_label.text = tel;
    }
    
    NSString *addr = [[NSUserDefaults standardUserDefaults]objectForKey:@"地址"];
    if (addr) {
        self.addr_label.text = addr;
    }
    
//     [NSString stringWithFormat:@"性别: %@ ,年龄 : %@ ",[[NSUserDefaults standardUserDefaults]objectForKey:@"性别"],[[NSUserDefaults standardUserDefaults]objectForKey:@"年龄"]];
    
    NSString *sexStr = [[NSUserDefaults standardUserDefaults]objectForKey:@"性别"];
    NSString *ageStr = [[NSUserDefaults standardUserDefaults]objectForKey:@"年龄"];
    if (sexStr && ageStr) {
        self.sex_label.text = [NSString stringWithFormat:@"性别: %@ ,年龄 : %@ ",sexStr,ageStr];
    }
    [self layoutIfNeeded];
    
    
    }

-(void)layoutSubviews{
    [super layoutSubviews];
    self.picImageView.layer.cornerRadius = 45;
    self.picImageView.layer.masksToBounds = YES;
    
}



@end
